<%@ Page Title="Manage Farms" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="ManageFarms.aspx.cs" Inherits="NIntegrate.Configuration.UI.ManageFarms" MaintainScrollPositionOnPostback="true" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <h2>Manage Farms</h2>
    <div class="bottomhyperlink"><img alt="Add new farm" src="Images/plus.gif" /><asp:LinkButton 
            ID="btnShowAddNewPanel" runat="server" Text="Add new farm" 
            onclick="btnShowAddNewPanel_Click"></asp:LinkButton></div>
    <br />
    <asp:GridView CssClass="gridview"
        ID="gvFarms" runat="server" 
        DataSourceID="dsFarms"
        DataKeyNames="Farm_id"
        AllowSorting="true"
        AutoGenerateDeleteButton="true"
        AutoGenerateColumns="false"
        AutoGenerateEditButton="true" onrowcommand="gvFarms_RowCommand">
        <Columns>
            <asp:TemplateField HeaderText="FarmName" SortExpression="FarmName">
                <ItemTemplate>
                    <%#Eval("FarmName") %>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="tbFarmName" runat="server" MaxLength="50" Text='<%#Bind("FarmName") %>'></asp:TextBox>
                    <asp:RequiredFieldValidator ID="tbFarmNameRequired" runat="server"
                        ControlToValidate="tbFarmName" EnableClientScript="false"
                        ErrorMessage="Required"></asp:RequiredFieldValidator>
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="FarmAddress" SortExpression="FarmAddress">
                <ItemTemplate>
                    <%#Eval("FarmAddress")%>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="tbFarmAddress" runat="server" Text='<%#Bind("FarmAddress") %>'></asp:TextBox>
                    <asp:RequiredFieldValidator ID="tbFarmAddressRequired" runat="server"
                        ControlToValidate="tbFarmAddress" EnableClientScript="false"
                        ErrorMessage="Required"></asp:RequiredFieldValidator>
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Environment" SortExpression="Environment_id">
                <ItemTemplate>
                    <asp:DropDownList ID="ddlEnvironments" runat="server" SelectedValue='<%# Bind("Environment_id") %>' DataSourceID="dsEnvironments" DataTextField="Name" DataValueField="Environment_id" Enabled="false"></asp:DropDownList>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:DropDownList ID="ddlEnvironments" runat="server" SelectedValue='<%# Bind("Environment_id") %>' DataSourceID="dsEnvironments" DataTextField="Name" DataValueField="Environment_id"></asp:DropDownList>
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Servers">
                <ItemTemplate>
                    <asp:LinkButton ID="btnViewServers" runat="server" Text="Manage Servers" CommandName="Select" CommandArgument='<%# "ViewServers|" + Eval("Farm_id") %>'></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Accessibility">
                <ItemTemplate>
                    <asp:LinkButton ID="btnEditFarmAccess" runat="server" Text="Manage Accessibility" CommandName="Select" CommandArgument='<%# "EditFarmAccess|" + Eval("Farm_id") %>'></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <SelectedRowStyle BackColor="LightYellow" />
    </asp:GridView>
    <asp:Panel ID="panelBottom" runat="server" CssClass="panelBottom">
        <asp:DetailsView ID="dvAddFarm" runat="server" Visible="false"
            DataSourceID="dsFarms" DefaultMode="Insert"
            AutoGenerateRows="false"
            AutoGenerateInsertButton="true"
            CssClass="detailstable" onitemcommand="dvAddFarm_ItemCommand" 
            oniteminserted="dvAddFarm_ItemInserted">
            <Fields>
                <asp:TemplateField HeaderText="FarmName">
                    <InsertItemTemplate>
                        <asp:TextBox ID="tbFarmName" runat="server" MaxLength="50" Text='<%#Bind("FarmName") %>'></asp:TextBox>
                        <asp:RequiredFieldValidator ID="tbFarmNameRequired" runat="server"
                            ControlToValidate="tbFarmName" EnableClientScript="false"
                            ErrorMessage="Required"></asp:RequiredFieldValidator>
                    </InsertItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="FarmAddress">
                    <InsertItemTemplate>
                        <asp:TextBox ID="tbFarmAddress" runat="server" Text='<%#Bind("FarmAddress") %>'></asp:TextBox>
                        <asp:RequiredFieldValidator ID="tbFarmAddressRequired" runat="server"
                            ControlToValidate="tbFarmAddress" EnableClientScript="false"
                            ErrorMessage="Required"></asp:RequiredFieldValidator>
                    </InsertItemTemplate>
                </asp:TemplateField>
            <asp:TemplateField HeaderText="Environment">
                <InsertItemTemplate>
                    <asp:DropDownList ID="ddlEnvironments" runat="server" SelectedValue='<%# Bind("Environment_id") %>' DataSourceID="dsEnvironments" DataTextField="Name" DataValueField="Environment_id"></asp:DropDownList>
                </InsertItemTemplate>
            </asp:TemplateField>                
            </Fields>
        </asp:DetailsView>
        <asp:Panel ID="panelServers" runat="server" Visible="false">
            <div class="bottomhyperlink"><img alt="Add new server" src="Images/plus.gif" /><asp:LinkButton 
                    ID="btnShowSubAddNewPanel" runat="server" Text="Add new server" 
                    onclick="btnShowSubAddNewPanel_Click"></asp:LinkButton></div>
            <br />
            <asp:GridView CssClass="gridview"
                ID="gvServers" runat="server" 
                DataSourceID="dsServers"
                DataKeyNames="Server_id"
                AllowSorting="true"
                AutoGenerateDeleteButton="true"
                AutoGenerateColumns="false"
                EmptyDataText="No servers in selected farm"
                AutoGenerateEditButton="true" onrowcommand="gvServers_RowCommand">
                <Columns>
                    <asp:TemplateField HeaderText="ServerName" SortExpression="ServerName">
                        <ItemTemplate>
                            <%#Eval("ServerName")%>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="tbServerName" runat="server" MaxLength="50" Text='<%#Bind("ServerName") %>'></asp:TextBox>
                            <asp:RequiredFieldValidator ID="tbServerNameRequired" runat="server"
                                ControlToValidate="tbServerName" EnableClientScript="false"
                                ErrorMessage="Required"></asp:RequiredFieldValidator>
                        </EditItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="ServerAddress" SortExpression="ServerAddress">
                        <ItemTemplate>
                            <%#Eval("ServerAddress")%>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="tbServerAddress" runat="server" Text='<%#Bind("ServerAddress") %>'></asp:TextBox>
                            <asp:RequiredFieldValidator ID="tbServerAddressRequired" runat="server"
                                ControlToValidate="tbServerAddress" EnableClientScript="false"
                                ErrorMessage="Required"></asp:RequiredFieldValidator>
                        </EditItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Farm">
                        <ItemTemplate>
                            <asp:DropDownList ID="ddlFarms" runat="server" SelectedValue='<%# Bind("Farm_id") %>' DataSourceID="dsFarms" DataTextField="FarmName" DataValueField="Farm_id" Enabled="false"></asp:DropDownList>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:DropDownList ID="ddlFarms" runat="server" SelectedValue='<%# Bind("Farm_id") %>' DataSourceID="dsFarms" DataTextField="FarmName" DataValueField="Farm_id"></asp:DropDownList>
                        </EditItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
            <asp:Panel ID="panelAddServer" runat="server" CssClass="panelBottom" Visible="false">
                <asp:DetailsView ID="dvAddServer" runat="server"
                    DataSourceID="dsServers" DefaultMode="Insert"
                    AutoGenerateRows="false"
                    AutoGenerateInsertButton="true"
                    CssClass="detailstable" onitemcommand="dvAddServer_ItemCommand" 
                    oniteminserted="dvAddServer_ItemInserted" 
                    ondatabound="dvAddServer_DataBound">
                    <Fields>
                        <asp:TemplateField HeaderText="ServerName">
                            <InsertItemTemplate>
                                <asp:TextBox ID="tbServerName" runat="server" MaxLength="50" Text='<%#Bind("ServerName") %>'></asp:TextBox>
                                <asp:RequiredFieldValidator ID="tbServerNameRequired" runat="server"
                                    ControlToValidate="tbServerName" EnableClientScript="false"
                                    ErrorMessage="Required"></asp:RequiredFieldValidator>
                            </InsertItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="ServerAddress">
                            <InsertItemTemplate>
                                <asp:TextBox ID="tbServerAddress" runat="server" Text='<%#Bind("ServerAddress") %>'></asp:TextBox>
                                <asp:RequiredFieldValidator ID="tbServerAddressRequired" runat="server"
                                    ControlToValidate="tbServerAddress" EnableClientScript="false"
                                    ErrorMessage="Required"></asp:RequiredFieldValidator>
                            </InsertItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Farm">
                            <InsertItemTemplate>
                                <asp:DropDownList ID="ddlFarms" runat="server" SelectedValue='<%# Bind("Farm_id") %>' DataSourceID="dsFarms" DataTextField="FarmName" DataValueField="Farm_id"></asp:DropDownList>
                            </InsertItemTemplate>
                        </asp:TemplateField>              
                    </Fields>
                </asp:DetailsView>            
            </asp:Panel>
        </asp:Panel>
        <asp:GridView ID="gvFarmAccess" runat="server" CssClass="gridview" ShowHeader="false"
            DataSourceID="dsFarms" AutoGenerateColumns="false" Visible="false"
            onrowcommand="gvFarmAccess_RowCommand" 
            onrowdatabound="gvFarmAccess_RowDataBound">
            <Columns>
                <asp:BoundField DataField="FarmName"/>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:CheckBox ID="cbMSMQ" runat="server" Text="MSMQ" /><asp:Button ID="btnMSMQ" runat="server" CssClass="hidden" CommandName="MSMQ" CommandArgument='<%# Eval("Farm_id") %>' />
                        <asp:CheckBox ID="cbHTTP" runat="server" Text="HTTP" /><asp:Button ID="btnHTTP" runat="server" CssClass="hidden" CommandName="HTTP" CommandArgument='<%# Eval("Farm_id") %>' />
                        <asp:CheckBox ID="cbTCP" runat="server" Text="TCP" /><asp:Button ID="btnTCP" runat="server" CssClass="hidden" CommandName="TCP" CommandArgument='<%# Eval("Farm_id") %>' />
                        <asp:CheckBox ID="cbIPC" runat="server" Text="IPC" /><asp:Button ID="btnIPC" runat="server" CssClass="hidden" CommandName="IPC" CommandArgument='<%# Eval("Farm_id") %>' />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </asp:Panel>
    <asp:HiddenField ID="hidSelectedFarm_id" runat="server" />
    <asp:HiddenField ID="hidFarmAccessItemChecked" runat="server" Value="False" />    
    <ni:QueryDataSource ID="dsFarms" runat="server" UseLocalQueryService="true">
    </ni:QueryDataSource>
    <ni:QueryDataSource ID="dsEnvironments" runat="server" UseLocalQueryService="true">
    </ni:QueryDataSource>
    <ni:QueryDataSource ID="dsServers" runat="server" UseLocalQueryService="true" 
        oninserting="dsServers_Inserting" onupdating="dsServers_Updating">
    </ni:QueryDataSource>
</asp:Content>
